﻿
Imports System.IO
Imports System.Windows.Forms
Imports System.Xml
Imports System.Xml.Serialization

Public Class MyXML


    ' Save an object out to the disk
    Public Shared Sub SerializeObject(Of T)(toSerialize As T, filename As [String])
        Dim xmlSerializer As New XmlSerializer(toSerialize.[GetType]())
        Using textWriter As TextWriter = New StreamWriter(filename)
            xmlSerializer.Serialize(textWriter, toSerialize)
        End Using
    End Sub

    ' Load an object from the disk
    Private Shared Function DeserialzeObject(Of T As Class)(filename As [String]) As T
        Dim xmlSerializer As New XmlSerializer(GetType(T))
        Try
            Using textReader As TextReader = New StreamReader(filename)
                Return DirectCast(xmlSerializer.Deserialize(textReader), T)
            End Using
        Catch generatedExceptionName As FileNotFoundException
        End Try
        Return Nothing
    End Function



End Class
